<?php
if($levelTL != 3) {
	die("Bạn không đủ quyền để truy cập trang này!");
}
$total = m_get_config('total_server_media');
    if (!$_POST['submit']) {
    ?>
    <form method="post">
	<div class="content_block">
		<div class="form_tbl" id="slides">
			<span class="border_d clearfix"> 
				<div class="form_item">
					<label><span class="required_marker">*</span> Tổng số server:</label>
					<input class="flat" size="5" name="s_total_server_media" value="<?=$total;?>" maxlength="99">
				</div>
				<? for ($x=1; $x<=$total; $x++) {
                $server_url_[$x] = m_get_config('server_url_'.$x);
                $server_folder_[$x] = m_get_config('server_folder_'.$x);  ?>
				<div class="form_item"><label></label><strong>Sever <?=$x?></strong></div>
				<div class="form_item">
					<label><span class="required_marker">*</span>Link Host:</label>
					<input name="s_url_[<?=$x?>]" size="32" value="<?=$server_url_[$x]?>">
				</div>
				<div class="form_item">
					<label><span class="required_marker">*</span>Folder:</label>
					<input name="s_folder_[<?=$x?>]" size="50" value="<?=$server_folder_[$x]?>">
				</div>
                <? } ?>
                <div class="form_item">
							<label style="color:#777;padding-top:10px;"></label>
							<span onmouseout="this.className='mb_btn1'" onmouseover="this.className='mb_btn1_hover'" class="mb_btn1">
								<button value="Submit" name="submit" type="submit">Sửa server</button>
							</span>
				</div>
            </span>
    	</div>
    </div>
    </form>
    <?php
    }
    else {    
        for ($y=1; $y<=$total; $y++) {
            $server_url_gan = 'server_url_'.$y;
            $server_folder_gan = 'server_folder_'.$y;
			$db->dbupdate("config","cf_value = '".$s_url_[$y]."'","cf_name IN ('".$server_url_gan."')");
			$db->dbupdate("config","cf_value = '".$s_folder_[$y]."'","cf_name IN ('".$server_folder_gan."')");
        }
        if ($s_total_server_media > $total) {
            for ($i=$total+1; $i<=$s_total_server_media; $i++) {
				$db->dbinstall("config","cf_name,cf_value","'server_url_".$i."',''");
				$db->dbinstall("config","cf_name,cf_value","'server_folder_".$i."',''");
            }
        }
        elseif ($s_total_server_media < $total) {
            for ($i=$s_total_server_media+1; $i<=$total; $i++) {
                $server_url_addon = 'server_url_'.$i;
                $server_folder_addon = 'server_folder_'.$i;
				$db->dbdelete("config","config_name IN ('".$server_url_addon."')");
				$db->dbdelete("config","config_name IN ('".$server_folder_addon."')");
            }
        }
        if ($s_total_server_media <= 0)
        $s_total_server_media = 1;
		$db->dbupdate("config","cf_value = '".$s_total_server_media."'","cf_name = 'total_server_media'");
        header("Location: ?ipos=server");
    }
?>